﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using YiSha.Util;
using YiSha.Util.Extension;
using YiSha.Util.Model;
using YiSha.Entity.OrganizationManage;
using YiSha.Model.Param.OrganizationManage;
using YiSha.Service.OrganizationManage;

namespace YiSha.Business.OrganizationManage
{
    /// <summary>
    /// 创 建：admin
    /// 日 期：2020-05-09 22:53
    /// 描 述：营销网络业务类
    /// </summary>
    public class NetworkBLL
    {
        private NetworkService networkService = new NetworkService();

        #region 获取数据
        public async Task<TData<List<NetworkEntity>>> GetList(NetworkListParam param)
        {
            TData<List<NetworkEntity>> obj = new TData<List<NetworkEntity>>();
            obj.Result = await networkService.GetList(param);
            obj.TotalCount = obj.Result.Count;
            obj.Tag = 1;
            return obj;
        }

        public async Task<TData<List<NetworkEntity>>> GetPageList(NetworkListParam param, Pagination pagination)
        {
            TData<List<NetworkEntity>> obj = new TData<List<NetworkEntity>>();
            obj.Result = await networkService.GetPageList(param, pagination);
            obj.TotalCount = pagination.TotalCount;
            obj.Tag = 1;
            return obj;
        }
        //public async Task<TData<List<NetworkEntity>>> GetPageList(NetworkListParam param, Pagination pagination)
        //{
        //    TData<List<NetworkEntity>> obj = new TData<List<NetworkEntity>>();
        //    if (param?.ProvinceId != null)
        //    {
        //        param.ChildrenAreaIdList = await departmentBLL.GetChildrenDepartmentIdList(null, param.ProvinceId.Value);
        //    }
        //    else
        //    {

        //        OperatorInfo user = await Operator.Instance.Current();
        //        param.ChildrenDepartmentIdList = await departmentBLL.GetChildrenDepartmentIdList(null, user.DepartmentId.Value);
        //    }
        //    obj.Result = await userService.GetPageList(param, pagination);
        //    List<UserBelongEntity> userBelongList = await userBelongService.GetList(new UserBelongEntity { UserIds = obj.Result.Select(p => p.Id.Value).ParseToStrings<long>() });
        //    List<DepartmentEntity> departmentList = await departmentService.GetList(new DepartmentListParam { Ids = userBelongList.Select(p => p.BelongId.Value).ParseToStrings<long>() });
        //    foreach (UserEntity user in obj.Result)
        //    {
        //        user.DepartmentName = departmentList.Where(p => p.Id == user.DepartmentId).Select(p => p.DepartmentName).FirstOrDefault();
        //    }
        //    obj.TotalCount = pagination.TotalCount;
        //    obj.Tag = 1;
        //    return obj;
        //}

        public async Task<TData<NetworkEntity>> GetEntity(long id)
        {
            TData<NetworkEntity> obj = new TData<NetworkEntity>();
            obj.Result = await networkService.GetEntity(id);
            if (obj.Result != null)
            {
                obj.Tag = 1;
            }
            return obj;
        }
        #endregion

        #region 提交数据
        public async Task<TData<string>> SaveForm(NetworkEntity entity)
        {
            TData<string> obj = new TData<string>();
            await networkService.SaveForm(entity);
            obj.Result = entity.Id.ParseToString();
            obj.Tag = 1;
            return obj;
        }

        public async Task<TData> DeleteForm(string ids)
        {
            TData obj = new TData();
            await networkService.DeleteForm(ids);
            obj.Tag = 1;
            return obj;
        }
        #endregion

        #region 私有方法
        #endregion
    }
}
